package com.spzx.cart.api.factory;

import com.spzx.cart.api.RemoteCartService;
import com.spzx.cart.api.domain.CartInfo;
import com.spzx.common.core.constant.ServiceNameConstants;
import com.spzx.common.core.domain.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;

import java.util.List;

/**
* 购物车降级处理
*/
public class RemoteCartFallbackFactory implements FallbackFactory<RemoteCartService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteCartFallbackFactory.class);
    @Override
    public RemoteCartService create(Throwable cause) {
        log.info("远程调用["+ ServiceNameConstants.CART_SERVICE +"]服务失败了:");
        return new RemoteCartService() {
            @Override
            public R<List<CartInfo>> getCartCheckedList(Long userId, String source) {
                return R.fail("获取用户购物车选中数据降级处理");
            }

            @Override
            public R<Boolean> updateCartPrice(Long userId, String source) {
                return R.fail("更新购物车价格降级处理");
            }

            @Override
            public R<Boolean> deleteCartCheckedList(Long userId, String source) {
                return R.fail("删除购物选中数据降级处理");
            }
        };
    }
}
